package org.busalerter.ui;

import javax.swing.*;
import java.awt.*;


/**
 * Created by IntelliJ IDEA.
 * User: Andy
 * Date: 20/11/11
 * Time: 18:02
 * To change this template use File | Settings | File Templates.
 */
public class SwingUtils {

    // Standard Open Behavior *************************************************

    protected static void packAndShowOnScreenCenter(JFrame frame) {
        frame.pack();
        locateOnOpticalScreenCenter(frame);
        frame.setVisible(true);
    }

    protected static void packAndShowOnScreenCenter(JDialog frame) {
        frame.pack();
        locateOnOpticalScreenCenter(frame);
        frame.setVisible(true);
    }

    protected static void packAndPositionOnScreenCenter(JDialog frame) {
        frame.pack();
        locateOnOpticalScreenCenter(frame);
    }
    // Screen Position ********************************************************

    /**
     * Locates the given component on the screen's center.
     *
     * @param component   the component to be centered
     */
    protected static void locateOnOpticalScreenCenter(java.awt.Component component) {
        Dimension paneSize = component.getSize();
        Dimension screenSize = component.getToolkit().getScreenSize();
        component.setLocation((screenSize.width  - paneSize.width)  / 2,
                              (int) ((screenSize.height - paneSize.height) * 0.45));
    }

}
